3.2. Fold Expression(폴드 표현식)
가변 인자 템플릿에 대해 ...으로 단순화 시킬 수 있는 기능
// 1. 역직렬화 자동화
template<typename... Args>
bool TryDeserialize(EPropertyType TargetType, FBinaryReader& Reader, std::variant<Args...>& OutValue) {
// variant에 포함된 모든 Args들에 대해 람다 실행
return ((PropertyTraits<Args>::Type == TargetType ?
(Args temp, Reader >> temp, OutValue = temp, true) : false) || ...);
}
// 2. 직렬화 자동화 (XML Tag -> Enum)
template<typename... Args>
EPropertyType GetTypeFromTag(const std::string& Tag) {
EPropertyType result = EPropertyType::EPT_TypeNum;
((Tag == PropertyTraits<Args>::Tag ? (result = PropertyTraits<Args>::Type, true) : false) || ...);
return result;
}